﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq;
using System.Text;
using Galoap.JSON;
using Galoap;
using Galoap.Properties;
using Galoap.UnitTest.Storage;
using Galoap.Questions;
using Galoap.UnitTest;
using Galoap.Workflow;
using Galoap.Workflow.Model;
using Galoap.Workflow.ParseScxml;

public partial class Rank : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Hashtable lista = new Hashtable();
        string risposta = "";
        string richiesta = Request.Params[0].ToString();
        lista = (Hashtable)JSON.JsonDecode(richiesta);
        try
        {
            string type = (string)lista["event"];
            if(type == "rank"){
                Game g = Galoap.Game.GetGame(4);
                List<UserGame> u = Galoap.User.GetRanking(g);
                risposta = "{\"TagImage\": 0";
                foreach (UserGame us in u) {
                    us.UserReference.Load();
                    
                    risposta+=",\""+us.User.NickName+"\":"+(int)(us.ranking*100);
                }

                risposta += "}";
                //risposta = "{\"Tizio\":" + 10 + ",\"Caio\":" + 2 * 10 + ",\"Sempronio\":" + 3 * 10 + "}";
            }
        }
        catch (NullReferenceException) { return; }
        Response.Write(risposta);
        Response.End();
    }
}
